package com.zyh.scs.admin.base;

import com.zyh.scs.admin.api.constant.CodeSet;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;

/**
 * 泛微同步数据返回
 *
 * @author hwh
 */
@Data
@ToString
public class LaoSheFanWeiResponse<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected Integer retCode;

	protected String retMsg;
	
	protected T data;
	
	
	public LaoSheFanWeiResponse(){
		this.retCode = CodeSet.SYSTEM_ERR_CODE.getCode();
		this.retMsg = "处理失败";
	}
	
	public LaoSheFanWeiResponse(Integer code, String msg){
		this.retCode = code;
		this.retMsg = msg;
	}
	
	public static <T> LaoSheFanWeiResponse<T> success(String msg){
		LaoSheFanWeiResponse<T> result = new LaoSheFanWeiResponse<>();
		result.setRetCode(CodeSet.SUCCESS_CODE.getCode());
		result.setRetMsg(msg);
		return result;
	}

	public static <T> LaoSheFanWeiResponse<T> successData(T object){
		LaoSheFanWeiResponse<T> result = new LaoSheFanWeiResponse<>();
		result.setRetCode(CodeSet.SUCCESS_CODE.getCode());
		result.setData(object);
		result.setRetMsg("处理成功");
		return result;
	}

	public static <T> LaoSheFanWeiResponse<T> error(CodeSet codeSet){
		LaoSheFanWeiResponse<T> result = new LaoSheFanWeiResponse<>();
		result.setRetCode(codeSet.getCode());
		result.setRetMsg(codeSet.getCodeName());
		return result;
	}


	public static <T> LaoSheFanWeiResponse<T> error(Integer retCode, String retMsg){
		LaoSheFanWeiResponse<T> result = new LaoSheFanWeiResponse<>();
		result.setRetCode(retCode);
		result.setRetMsg(retMsg);
		return result;
	}

	public static <T> LaoSheFanWeiResponse<T> error() {
		LaoSheFanWeiResponse<T> result = new LaoSheFanWeiResponse<>();
		result.setRetCode(CodeSet.SYSTEM_ERR_CODE.getCode());
		result.setRetMsg("系统处理失败");
		return result;
	}

	public void setCodeSet(CodeSet codeSet) {
		this.setRetCode(codeSet.getCode());
		this.setRetMsg(codeSet.getCodeName());
	}

}